#!/usr/bin/env ruby

# Run it like this:
#
#   ./codegen/mappable_generator.rb > src/main/scala/com/twitter/scalding/GeneratedMappable.scala

$indent = "  "

TYPES = ('A'..'Z').to_a

def make_mappable(cnt)
  other_cnts = (1..(22-cnt)).to_a
  typeString = TYPES[0..(cnt - 1)].join(",")
  puts "trait Mappable#{cnt}[#{typeString}] extends Mappable[Tuple#{cnt}[#{typeString}]] {"
  puts "#{$indent}def converter[Z >: Tuple#{cnt}[#{typeString}]] = TupleConverter.asSuperConverter(TupleConverter.of[Tuple#{cnt}[#{typeString}]])"
  puts "}"
end

puts "// following were autogenerated by #{__FILE__} at #{Time.now} do not edit"
puts %q|package com.twitter.scalding

|

(1..22).each { |c|
  make_mappable(c)
  puts
}

puts "// end of autogenerated"
